package org.roger.search;

import java.io.IOException;

import org.apache.lucene.index.Term;
import org.apache.lucene.search.Filter;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.payloads.AveragePayloadFunction;
import org.apache.lucene.search.payloads.PayloadTermQuery;

/**
 * 利用有效载荷搜索
 * @author luoweiyi
 */
public class PayloadSearch extends LuceneSearchBase{
	
	private String field;
	
	private String keyword;
	
	public PayloadSearch(String field,String keyword){
		this.field = field;
		this.keyword = keyword;
	}

	@Override
	public Query getSearchQuery() {
		Term term = new Term(field,keyword);
		//term.
		PayloadTermQuery query = new PayloadTermQuery(term,new AveragePayloadFunction());
		
		//PayloadNearQuery query = new PayloadNearQuery();
		return query;
	}

	@Override
	public Filter getFilter() {
		return null;
	}

	@Override
	public Sort getSort() {
		return null;
	}
	
	public static void main(String[] args) {
		PayloadSearch search = new PayloadSearch("contents","your");
		try {
			search.search("D:/index2");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
